package com.jeeplus.test.jlnu.admissionInfo.service.impl;

import com.jeeplus.test.jlnu.admissionInfo.domain.entity.AdmissionInfo;
import com.jeeplus.test.jlnu.admissionInfo.mapper.ExcelMapper;
import com.jeeplus.test.jlnu.admissionInfo.service.AdmissionExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AdmissionExcelServiceImpl implements AdmissionExcelService {

    @Autowired
    private ExcelMapper excelMapper;

    @Override
    public void insertDataAdmission(List<AdmissionInfo> admissionInfos) {
        // 插入录取信息表全部数据
        excelMapper.saveFirstData(admissionInfos);
        // 插入学籍信息表（只插入学号）
        excelMapper.saveSecondData(admissionInfos);
        // 插入毕业信息表（只插入学号）
//        excelMapper.saveThirdData(admissionInfos);
        // 插入就业信息表（只插入学号）
        excelMapper.saveFourth(admissionInfos);
        // 插入学位信息表（只插入学号）
        excelMapper.saveFifth(admissionInfos);
        // 插入学历信息表（只插入学号）
        excelMapper.saveSixth(admissionInfos);
        // 插入转递（邮寄信息表）
        excelMapper.saveSeventh(admissionInfos);
        // 档案信息表
//        excelMapper.saveEighth(admissionInfos);
        //往学生端插入学号数据
        // 创建两个列表来存储不同 flag 的对象
        excelMapper.saveFourteenth(admissionInfos);
        excelMapper.saveFifteenth(admissionInfos);
        List<AdmissionInfo> flagOneList = new ArrayList<>();
        List<AdmissionInfo> otherFlagList = new ArrayList<>();

        for (AdmissionInfo admissionInfo : admissionInfos) {
            if ("1".equals(admissionInfo.getFlag())) {
                flagOneList.add(admissionInfo);
            } else {
                otherFlagList.add(admissionInfo);
            }
        }

        // 对于 flag 为 1 的对象调用保存方法
        if (!flagOneList.isEmpty()) {
            excelMapper.saveNinth(flagOneList);
            excelMapper.saveTenth(flagOneList);
            excelMapper.saveEleth(flagOneList);
            excelMapper.saveThirteenth(flagOneList);
        }

        // 对于 flag 为 2 或其他的对象调用保存方法
        if (!otherFlagList.isEmpty()) {
            excelMapper.saveTwelfth(otherFlagList);
            excelMapper.saveSixteenth(otherFlagList);
            excelMapper.saveSeventeenth(otherFlagList);
            excelMapper.saveEighteenth(otherFlagList);
        }
    }
}
